const state = {
  associatedRowList: new Map(),
}
const mutations = {
  /* 关联 */
  ASSOCIATED_GOODS: (state, data) => {
    let { row } = data
    let name = getAssociatedKeyFunc(data);
    state.associatedRowList.set(row[name], row)
  },
  /* 取消关联 */
  CANCEL_GOODS: (state, data) => {
    let { row } = data
    let name = getAssociatedKeyFunc(data);
    state.associatedRowList.delete(row[name])
  },
  /* 清空 */
  CLEAR_GOODS: (state, data) => {
    state.associatedRowList.clear()
  },
}
const getAssociatedKeyFunc = (data) => {
  let { row, type, typeList } = data;
  let key = 'uuid';
  if (typeList) {
    typeList.reduce((value, item) => {
      value += row[item];
      return value;
    }, '');
  }
  if (type) {
    key = type;
  }
  return key;
}
export default {
  namespaced: true,
  state,
  mutations
}
